package com.qhzz.permissionlib;

import android.app.Activity;
import android.content.Context;
import android.support.v4.app.Fragment;

import com.qhzz.permissionlib.source.AppActivitySource;
import com.qhzz.permissionlib.source.AppFragmentSource;
import com.qhzz.permissionlib.source.ContextSource;
import com.qhzz.permissionlib.source.Source;
import com.qhzz.permissionlib.source.SupportFragmentSource;

public class AndPermission {
    public static ProcessRequest with(Context context) {
        return new ProcessRequest(new ContextSource(context));
    }

    public static ProcessRequest with(Activity activity) {
        return new ProcessRequest(new AppActivitySource(activity));
    }

    public static ProcessRequest with(Fragment fragment) {
        return new ProcessRequest(new SupportFragmentSource(fragment));
    }

    public static ProcessRequest with(android.app.Fragment fragment) {
        return new ProcessRequest(new AppFragmentSource(fragment));
    }
    //
    public static boolean hasAlwaysDeniedPermission(Source source, String... deniedPermissions) {
        for (String permission : deniedPermissions) {
            if (!source.isShowRationalePermission(permission)) {
                return true;
            }
        }
        return false;
    }
}
